package com.example.association2.service;

import com.example.association2.model.*;
import com.example.association2.repository.AssociationRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
public class AssociationServiceImpl implements AssociationService {
    @Autowired
    private AssociationRepository associationRepository;
    @Override
    public List<Association> findAllAssociations() {
        return associationRepository.findAllAssociations();
    }

    @Override
    public List<Association> findAssociationsByType(int type) {
        return associationRepository.findAssociationsByType(type);
    }

    @Override
    public List<Association> findAssociationsByIdType(int userId, int type) {
        return associationRepository.findAssociationsByIdType(userId,type);
    }

    @Override
    public Association findAssociationById(int associationId) {
        return associationRepository.findAssociationById(associationId);
    }

    @Override
    public List<String> findAssociationNameByAssociationId(int associationId) {
        return associationRepository.findAssociationNameByAssociationId(associationId);
    }

    @Override
    public void addAssociation(String description, String name, String createTime, int type, int ownerId,String logo) {
        associationRepository.addAssociation(description,name,createTime,type,ownerId,logo);
    }

    @Override
    public List<Association> findAllAss() {
        return associationRepository.findAllAss();
    }

    @Override
    public void addAss(String description, String name, String createTime, int type, int ownerId, String logo) {
        associationRepository.addAss(description,name,createTime,type,ownerId,logo);
    }

    @Override
    public void deleteAss(int associationId) {
        associationRepository.deleteAss(associationId);
    }

    @Override
    public List<Association> findAllAssociationsApply() {
        return associationRepository.findAllAssociationsApply();
    }

    @Override
    public void applyPass(String createTime,int associationId) {
        associationRepository.applyPass(createTime,associationId);
    }

    @Override
    public void applyRefuse(int associationId) {
        associationRepository.applyRefuse(associationId);
    }

    @Override
    public void assModify(String description, String name, int type, int ownerId, String logo,Integer signatureActivity,int associationId) {
        associationRepository.assModify(description,name,type,ownerId,logo,signatureActivity,associationId);
    }

    @Override
    public String findSignatureActivityName(int associationId) {
        return associationRepository.findSignatureActivityName(associationId);
    }

    @Override
    public Association findAssByUserId(int userId) {
        return associationRepository.findAssByUserId(userId);
    }

    @Override
    public int findOwnerIdByAssociationId(int associationId) {
        return associationRepository.findOwnerIdByAssociationId(associationId);
    }

    @Override
    public List<MyAssociationDTO> MyAssociation(int userId, int type){
        List<MyAssociationDTO> list = new ArrayList<>();
        if (type == 1){
            list =  associationRepository.MyAssociation(userId);
        }else {
            list =  associationRepository.MyArrAssociation(userId);
        }
        return list;
    }

    @Override
    public List<ReturnForm> NumOfAssType(){
        List<ReturnForm> returnForms = new ArrayList<>();
        List<SelectForm> list = associationRepository.numOfAssType();
        String name = "";
        for (int i = 0 ; i < list.size(); i++){
            ReturnForm returnForm = new ReturnForm();
            switch (list.get(i).getType()){
                case 1 : name = "文体类社团"; break;
                case 2 : name = "学术类社团"; break;
                case 3 : name = "公益类社团"; break;
                default: break;
            }
            returnForm.setValue(list.get(i).getNum());
            returnForm.setName(name);
            returnForms.add(returnForm);
        }
        return returnForms;
    }

    @Override
    public List<ReturnForm> NumOfActType(){
        List<ReturnForm> returnForms = new ArrayList<>();
        List<SelectForm> list = associationRepository.numOfActType();
        String name = "";
        for (int i = 0 ; i < list.size(); i++){
            ReturnForm returnForm = new ReturnForm();
            switch (list.get(i).getType()){
                case 1 : name = "文体类社团"; break;
                case 2 : name = "学术类社团"; break;
                case 3 : name = "公益类社团"; break;
                default: break;
            }
            returnForm.setValue(list.get(i).getNum());
            returnForm.setName(name);
            returnForms.add(returnForm);
        }
        return returnForms;
    }

    @Override
    public void addmessage(String  message, int associationId, int userId) {
//        log.info(""+message);
//        log.info(""+associationId);
//        log.info(""+userId);
        associationRepository.addmessage(message,associationId,userId);
    }

    @Override
    public List<Messages> getmessage(int associationId) {
//        log.info("{}",associationId);
//        log.info("{}",associationRepository.getmessage(associationId));
        return  associationRepository.getmessage(associationId);
    }
}
